package com.example.aicloud.controller;

import com.example.aicloud.entity.Comment;
import com.example.aicloud.service.ICommentService;
import com.example.aicloud.utils.Result;
import com.example.aicloud.utils.SecurityUtil;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Mr.Tang
 * @date 2024-08-03
 */
@RestController
@RequestMapping("/comment")
@AllArgsConstructor
public class CommentController {

    private final ICommentService commentService;

    /**
     * 添加评论
     */
    @RequestMapping("/addComment")
    public Result add(@Validated Comment comment) {
        comment.setUid(SecurityUtil.getCurrentUser().getUid());
        boolean save = commentService.save(comment);
        if (!save) {
            return Result.fail("添加失败，请重试");
        }
        return Result.success();
    }


}


